﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace Ebiz
{
    public partial class Logout : System.Web.UI.Page
    {
        public string strMsgs = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] == null){
                strMsgs = "You have successfully logout";
            }else{
                Dictionary<string, object> arrUserInfo = (Dictionary<string, object>)Session["UserInfo"];
                if (arrUserInfo["UID"] == null){
                    strMsgs = "You have successfully logout";
                }else{
                    FormsAuthentication.SignOut();
                    Session.Abandon();
                    Session.Clear();
                    //Session.Abandon();
                    
                    // Clear authentication cookie
                    HttpCookie rFormsCookie = new HttpCookie(FormsAuthentication.FormsCookieName, "");
                    rFormsCookie.Expires = DateTime.Now.AddYears(-1);
                    Response.Cookies.Add(rFormsCookie);

                    
                    // Clear session cookie 
                    HttpCookie rSessionCookie = new HttpCookie("ASP.NET_SessionId", "");
                    rSessionCookie.Expires = DateTime.Now.AddYears(-1);
                    Response.Cookies.Add(rSessionCookie);
                    
                    Response.ClearHeaders();
                    Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
                    Response.AddHeader("Pragma", "no-cache");

                    strMsgs = "You have successfully logout";
                }
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e){
            Response.Redirect("Default.aspx", true);
        }
    }
}
